use futures::executor::block_on;
use sgs_vm::core::{token::TokenDecoder, vm::Svm};
use std::env;

fn main(){
    
    let mut args: Vec<String> = vec![];
    let mut is_deug = false;
    for arg in env::args(){
        if arg.as_str() == "--debug"{
            is_deug = true;
        }
        args.push(arg);
    }
    if args.len() < 2 {
        println!("usage: sgvm <code-file>");
        return
    }
    let mut svm = Svm::new(is_deug);

    let res = std::fs::read_to_string(&args[1]);
    if let Ok(code) = res{
        let res = TokenDecoder::parse(code);
        match res {
            Ok(tokens) => {
                let f = svm.execute(tokens);
                block_on(f);
            }
            Err(e) => println!("svm: {}", e),
        }
    }else{
        println!("svm: code file not found {}",args[1]);
    }
      
}